import {createRouter, createWebHistory} from 'vue-router'
//不能懒加载
// import Home from '../views/Home.vue'
const Home = () => import('../views/Home')
const Category = () => import('../views/category/category')
const Detail = () => import('../views/detail/detail')
const Profile = () => import('../views/profile/profile')
const Shopcart = () => import('../views/shopcart/shopcart')

const routes = [
    {
        path: '',
        name: 'DefaultHome',
        component: Home,
        meta: {
            title: '图书兄弟',
        }
    },
    {
        path: '/',
        name: 'Home',
        component: Home,
        meta: {
            title: '图书兄弟',
        }
    },
    {
        path: '/category',
        name: 'Category',
        component: Category,
        meta: {
            title: '图书兄弟-商品分类',
        }
    },
    {
        path: '/detail',
        name: 'Detail',
        component: Detail,
        meta: {
            title: '图书兄弟-商品详情',
        }
    },
    {
        path: '/profile',
        name: 'Profile',
        component: Profile,
        meta: {
            title: '图书兄弟-个人中心',
        }
    },
    {
        path: '/shopcart',
        name: 'Shopcart',
        component: Shopcart,
        meta: {
            title: '图书兄弟-购物车',
        }
    },
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    //可以做登录拦截
    next()
    document.title = to.meta.title
})

export default router
